package com.kun.springcloudalibabaprovider.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@NacosPropertySource(dataId = "springcloud-alibaba-provider", autoRefreshed = true) // dataId为读取的配置id
public class ProviderController {

    /**
     * 读取nacos的配置，如果没有则默认为false
     * */
    @NacosValue(value = "${test.properties.useLocalCache:false}", autoRefreshed = true)
    private boolean useLocalCache;

    /**
     * 读取nacos的配置，如果没有则默认为无名氏
     * */
    @NacosValue(value = "${test.properties.defaultName:无名氏}", autoRefreshed = true)
    private String defaultName;

    @GetMapping("/get")
    public boolean get(){
        return useLocalCache;
    }

    @GetMapping("/hi")
    @SentinelResource(value = "hi") // 埋点
    public String hi() {
        return "hi " + defaultName;
    }

}
